﻿<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %><%@ page import="com.util.SuperString" %><%@ page import="java.util.List" %><%@page import="com.mtbu.service.DataUtil"%><%@page import="com.mtbu.bean.BppCata"%><%@include file="sys_commcheck.jsp"%>
<%
    response.setCharacterEncoding("utf-8");
    //response.setContentType("text/xml");
    String key = SuperString.notNullTrim(request.getParameter("key")).toLowerCase();
    String datatype = SuperString.notNullTrim(request.getParameter("datatype"));
    boolean isAll = true;
    boolean isRealTime = SuperString.getInt(request.getParameter("rt")) == 1;
    String exist_dataids = SuperString.notNullTrim(request.getParameter("exist_dataids"));
    List<String> listExistedIDS = SuperString.strToList(exist_dataids);
    StringBuffer sb = new StringBuffer(); 
    try {
        for(int i=0;i<DataUtil.getListBppCata().size();i++){
    		BppCata bc = DataUtil.getListBppCata().get(i);
        	StringBuffer parentsb = new StringBuffer();
        	StringBuffer childrensb = new StringBuffer();
        	boolean isHaveParent = false;
        	boolean isHaveChildren = false;
        	if(isAll || !key.equals("")){
            	sb.append("<div style=\"margin-bottom:5px;\">");
	        	if(listExistedIDS.contains(String.valueOf(bc.getId()))) {
	                //parentsb.append("<li>");
	                parentsb.append("<span class=\"comm_sel_div_xml_span_existed\">");
	                parentsb.append(bc.getTitle());
	                parentsb.append("</span><br/>");
	                //parentsb.append("</li>");
	            }else{
		    		parentsb.append("<span id=\"comm_sel_div_xml_span_");
		            parentsb.append(bc.getId());
		            parentsb.append("\" class=\"comm_sel_div_xml_span1\">");
		            parentsb.append("<span class=\"comm_sel_div_xml_span1_out\" onclick=\"clickCommData(");
		            parentsb.append(bc.getId());
		            parentsb.append(",'");
		            parentsb.append(SuperString.replace(bc.getTitle(),"'","\\'"));
		            parentsb.append("','");
		            parentsb.append(datatype);
		            parentsb.append("')\"");
		            parentsb.append(" onmouseover=\"this.className='comm_sel_div_xml_span1_over';\"");
		            parentsb.append(" onmouseout=\"this.className='comm_sel_div_xml_span1_out';\"");
		            parentsb.append(">");
		            parentsb.append(bc.getTitle());
		            parentsb.append("</span>");
		            parentsb.append("</span><br/>");
	            }
	        	if(key.length() == 0 ||
	                    (key.length() > 0 &&isRealTime && (bc.getTitle().toLowerCase().startsWith(key)
	                            || bc.getFirstPY().startsWith(key)))
	                    ||
	                    (key.length() > 0 &&!isRealTime && (bc.getTitle().toLowerCase().indexOf(key)>=0))
	                    ) {
	        		isHaveParent = true;	
	        	}
	    		if(bc.getSublist()!=null){
	   				for(int j=0;j<bc.getSublist().size();j++){
	   					if(key.length() == 0 ||
	   		                    (key.length() > 0 &&isRealTime && (bc.getSublist().get(j).getTitle().toLowerCase().startsWith(key)
	   		                            || bc.getSublist().get(j).getFirstPY().startsWith(key)))
	   		                    ||
	   		                    (key.length() > 0 &&!isRealTime && (bc.getSublist().get(j).getTitle().toLowerCase().indexOf(key)>=0))
	   		                    ) {
	   						isHaveChildren = true;
	   						if(isAll || !key.equals("")){
			   					if(listExistedIDS.contains(String.valueOf(bc.getSublist().get(j).getId()))) {
			   		                childrensb.append("<span class=\"comm_sel_div_xml_span_existed\">");
			   		                childrensb.append(bc.getSublist().get(j).getTitle());
			   		                childrensb.append("</span>");
			   		            }else{
				   					childrensb.append("<span id=\"comm_sel_div_xml_span_");
				   	                childrensb.append(bc.getSublist().get(j).getId());
				   	                childrensb.append("\" class=\"comm_sel_div_xml_span2\">");
				   	                childrensb.append("<span class=\"comm_sel_div_xml_span2_out\" onclick=\"clickCommData(");
				   	                childrensb.append(bc.getSublist().get(j).getId());
				   	                childrensb.append(",'");
				   	                childrensb.append(SuperString.replace(DataUtil.getMapBppCata().get(bc.getSublist().get(j).getPID()).getTitle()+ " > " +bc.getSublist().get(j).getTitle(),"'","\\'"));
				   	                childrensb.append("','");
				   	                childrensb.append(datatype);
				   	                childrensb.append("')\"");
				   	                childrensb.append(" onmouseover=\"this.className='comm_sel_div_xml_span2_over';\"");
				   	                childrensb.append(" onmouseout=\"this.className='comm_sel_div_xml_span2_out';\"");
				   	                childrensb.append(">");
				   	                childrensb.append(bc.getSublist().get(j).getTitle());
				   	                childrensb.append("</span>");
				   	                childrensb.append("</span>");
			   		            }
			   	                childrensb.append("&nbsp;&nbsp;&nbsp;");
	   						}
	   	                }
	   				}
	    		}
	            childrensb.append("<br/>");
	            if(isHaveChildren){
		            sb.append(parentsb.toString());
		            sb.append(childrensb.toString());
	            }
	            if(isHaveParent&&!isHaveChildren){
		            sb.append(parentsb.toString());            	
	            }
	            sb.append("</div>");
        	}
    	}
        if(!isAll && key.equals("")){
	    	sb.append("<div><hr/></div>");
	    	sb.append("<div style='text-align: right;padding-right:20px;'><span><a class=\"abutton\" href='javascript:void(0);' onclick=\"displayAllCata('"+datatype+"','"+exist_dataids+"')\">显示全部</a></span></div>");
        }
    } catch(Exception e) {
    } finally {
        out.print(sb.toString());
    }
%>